//
//  LoginViewController.swift
//  ChatTest
//
//  Created by kangqiao on 2021/9/6.
//

import UIKit
import KQChatSDK
import YYImage
class LoginViewController: UIViewController {

    @IBOutlet weak var img: UIImageView!
    @IBOutlet weak var mobileTF: UITextField!
    @IBOutlet weak var passTF: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.mobileTF.text = "15638259091"
        self.passTF.text = "66666"
        let urlStr = "https://im-static-test.hnkqwy.com/2021/09/13/09/mzmbmbPP-1-1631495398-p3T6scARO0aR.jpg?Expires=1634087399&OSSAccessKeyId=LTAI5tDjXkx1oq9YZ4Zp3G8i&Signature=%2FWcE9xPaWd%2F6ovwDQJbe95GkNm4%3D"
        guard let url = URL(string: urlStr) else { return }
        guard let d = try? Data.init(contentsOf: url) else { return }

        img.yy_setImage(with: url, placeholder: UIImage.init())
    }


    
    @IBAction func loginAction(_ sender: Any) {
        
        
        
        AppService.shared().login(mobileTF.text ?? "", password: passTF.text ?? "") { userId, token, newUser in
            WFCCNetworkService.sharedInstance().connect(userId , token: token )
            UserDefaults.standard.setValue(self.mobileTF.text ?? "", forKey: "savedName")
            UserDefaults.standard.setValue(token, forKey: "savedToken")
            UserDefaults.standard.setValue(userId, forKey: "savedUserId")
            UserDefaults.standard.synchronize()
            let chat = KQChatListViewController.init(shouldInit: true)
            self.navigationController?.pushViewController(chat, animated: true)
        } error: { errCode, message in
            print("message=====\(message)====code===\(errCode)")
        }

        
    }
    
}
